package com.keldian.myqq.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.keldian.myqq.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 15-11-16.
 */
public class Viewpager_activity extends Activity implements View.OnClickListener {

    @ViewInject(R.id.vp_startvp)
    ViewPager vp_statvp;
    @ViewInject(R.id.startBtn)
    Button startBtn;

    private List<View> list = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewpager_activity);
        ViewUtils.inject(this);
        initPager();

    }


    private void initPager() {
        LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());
        View view1 = layoutInflater.inflate(R.layout.viewpager_activity_item1, null);
        View view2 = layoutInflater.inflate(R.layout.viewpager_activity_item2, null);
        View view3 = layoutInflater.inflate(R.layout.viewpager_activity_item3, null);
        ViewUtils.inject(this, view3);
        startBtn.setOnClickListener(this);
        list.add(view1);
        list.add(view2);
        list.add(view3);


        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter();
        vp_statvp.setAdapter(viewPagerAdapter);
    }


    public class ViewPagerAdapter extends PagerAdapter {
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ((ViewGroup) container).addView(list.get(position));
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object o) {
            return view == o;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            ((ViewGroup) container).removeView(list.get(position));
        }
    }


    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }

    @OnClick(R.id.startBtn)
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.startBtn:
                Intent intent = new Intent(Viewpager_activity.this, WhatsNewDoor.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}
